package cn.peng.stu4teach.pages.main;

import androidx.databinding.library.baseAdapters.BR;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;

import cn.peng.stu4teach.R;
import cn.peng.stu4teach.databinding.ActivityMainBinding;
import cn.peng.stu4teach.pages.home.HomeFragment;
import cn.peng.stu4teach.util.base.BaseActivity;

/**
 * 首页Activity
 */
public class MainActivity extends BaseActivity<ActivityMainBinding, MainVm> {
    private final String          TAG = MainActivity.class.getSimpleName();

    @Override
    public int setLayoutId () {
        return R.layout.activity_main;
    }

    @Override
    public int setBrVmId () {
        return BR.vm;
    }

    @Override
    public MainVm setBrVm () {
        return new ViewModelProvider(this).get(MainVm.class);
    }

    @Override
    public void initData () {
        super.initData();

        FragmentManager fragmentManager = getSupportFragmentManager();

        // 默认展示 HomeFragment
        mVM.showFragment(HomeFragment.newInstance(), fragmentManager);

        // 监听 BottomNavigationView 的条目选中事件
        mBinding.btmNav.setOnItemSelectedListener(mVM.getBtmNvItemSelectedListener(fragmentManager));
    }
}
